home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / icmpdump.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  2KB  |  73 lines

  1. /* @(#) $Header: icmpdump.c,v 1.4 91/02/24 20:16:55 deyke Exp $ */
  2.  
  3. /* ICMP header tracing
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "internet.h"
  10. #include "netuser.h"
  11. #include "icmp.h"
  12. #include "trace.h"
  13. #include "ip.h"
  14.  
  15. /* Dump an ICMP header */
  16. void
  17. icmp_dump(fp,bpp,source,dest,check)
  18. FILE *fp;
  19. struct mbuf **bpp;
  20. int32 source,dest;
  21. int check;              /* If 0, bypass checksum verify */
  22. {
  23.     struct icmp icmp;
  24.     int16 csum;
  25.  
  26.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  27.         return;
  28.     csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  29.  
  30.     ntohicmp(&icmp,bpp);
  31.  
  32.     fprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  33.  
  34.     switch(uchar(icmp.type)){
  35.     case ICMP_DEST_UNREACH:
  36.         fprintf(fp," code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  37.         break;
  38.     case ICMP_REDIRECT:
  39.         fprintf(fp," code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  40.         fprintf(fp," new gateway %s",inet_ntoa(icmp.args.address));
  41.         break;
  42.     case ICMP_TIME_EXCEED:
  43.         fprintf(fp," code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  44.         break;
  45.     case ICMP_PARAM_PROB:
  46.         fprintf(fp," pointer %u",icmp.args.pointer);
  47.         break;
  48.     case ICMP_ECHO:
  49.     case ICMP_ECHO_REPLY:
  50.     case ICMP_INFO_RQST:
  51.     case ICMP_INFO_REPLY:
  52.     case ICMP_TIMESTAMP:
  53.     case ICMP_TIME_REPLY:
  54.         fprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  55.         break;
  56.     }
  57.     if(check && csum != 0){
  58.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  59.     }
  60.     putc('\n',fp);
  61.     /* Dump the offending IP header, if any */
  62.     switch(icmp.type){
  63.     case ICMP_DEST_UNREACH:
  64.     case ICMP_TIME_EXCEED:
  65.     case ICMP_PARAM_PROB:
  66.     case ICMP_QUENCH:
  67.     case ICMP_REDIRECT:
  68.         fprintf(fp,"Returned ");
  69.         ip_dump(fp,bpp,0);
  70.     }
  71. }
  72.  
  73.